package com.ruoyi.comn.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.comn.domain.ComnDeptTeams;
import com.ruoyi.comn.service.IComnDeptTeamsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 班组管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/comn/teams")
public class ComnDeptTeamsController extends BaseController
{
    @Autowired
    private IComnDeptTeamsService comnDeptTeamsService;

    /**
     * 查询班组管理列表
     */
    @PreAuthorize(hasPermi = "comn:teams:list")
    @GetMapping("/list")
    public TableDataInfo list(ComnDeptTeams comnDeptTeams)
    {
        startPage();
        List<ComnDeptTeams> list = comnDeptTeamsService.selectComnDeptTeamsList(comnDeptTeams);
        return getDataTable(list);
    }

    /**
     * 导出班组管理列表
     */
    @PreAuthorize(hasPermi = "comn:teams:export")
    @Log(title = "班组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComnDeptTeams comnDeptTeams) throws IOException
    {
        List<ComnDeptTeams> list = comnDeptTeamsService.selectComnDeptTeamsList(comnDeptTeams);
        ExcelUtil<ComnDeptTeams> util = new ExcelUtil<ComnDeptTeams>(ComnDeptTeams.class);
        util.exportExcel(response, list, "班组管理数据");
    }

    /**
     * 获取班组管理详细信息
     */
    @PreAuthorize(hasPermi = "comn:teams:query")
    @GetMapping(value = "/{deptTeamUuid}")
    public AjaxResult getInfo(@PathVariable("deptTeamUuid") String deptTeamUuid)
    {
        return AjaxResult.success(comnDeptTeamsService.selectComnDeptTeamsByDeptTeamUuid(deptTeamUuid));
    }

    /**
     * 新增班组管理
     */
    @PreAuthorize(hasPermi = "comn:teams:add")
    @Log(title = "班组管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComnDeptTeams comnDeptTeams)
    {
        return toAjax(comnDeptTeamsService.insertComnDeptTeams(comnDeptTeams));
    }

    /**
     * 修改班组管理
     */
    @PreAuthorize(hasPermi = "comn:teams:edit")
    @Log(title = "班组管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComnDeptTeams comnDeptTeams)
    {
        return toAjax(comnDeptTeamsService.updateComnDeptTeams(comnDeptTeams));
    }

    /**
     * 删除班组管理
     */
    @PreAuthorize(hasPermi = "comn:teams:remove")
    @Log(title = "班组管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deptTeamUuids}")
    public AjaxResult remove(@PathVariable String[] deptTeamUuids)
    {
        return toAjax(comnDeptTeamsService.deleteComnDeptTeamsByDeptTeamUuids(deptTeamUuids));
    }
}
